package com.xczz.common.security;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.xczz.model.SysUser;
import com.xczz.model.vo.SysUserVO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Set;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class LoginUser implements UserDetails {
    private static final long serialVersionUID=1L;
    private String token;
    private Long LoginTime;
    private Long expireTime;
    private String ipaddr;
    private String loginLocation;
    private String browser;
    private String os;
    private Set<String> permissions;
    private SysUserVO user;
    public LoginUser(SysUserVO user,Set<String> permissions){
        this.user=user;
        this.permissions=permissions;
    }

    @JsonIgnore
    @Override
    public String getPassword(){
        return user.getPassword();
    }

    @Override
    public String getUsername(){
        return user.getUserName();
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired(){
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired(){
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isEnabled(){
        return true;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities(){
        return null;
    }
}
